import {get, post} from '@/utils/request'

export default {
    namespaced: true,
    state: {
        dataList: []
    },
    getters: {
        confirmed(state) {
            if(state.dataList.list) {
                var result = 0
                state.dataList.list.forEach(item => {
                    result += item.confirmed
                })
                return result
            }
        },
        cure(state) {
            if(state.dataList.list) {
                var result = 0
                state.dataList.list.forEach(item => {
                    result += item.cure
                })
                return result
            }
        },
        dead(state) {
            if(state.dataList.list) {
                var result = 0
                state.dataList.list.forEach(item => {
                    result += item.dead
                })
                return result
            }
        },
        suspected(state) {
            if(state.dataList.list) {
                var result = 0
                state.dataList.list.forEach(item => {
                    result += item.suspected
                })
                return result
            }
        },
        severe(state) {
            if(state.dataList.list) {
                var result = 0
                state.dataList.list.forEach(item => {
                    result += item.severe
                })
                return result
            }
        },
        outside(state) {
            if(state.dataList.list) {
                var result = 0
                state.dataList.list.forEach(item => {
                    result += item.outside
                })
                return result
            }
        }
    },
    mutations: {
        refreshPageQueryData(state,data) {
            state.dataList = data
        }
    },
    actions: {
        // 保存
        async SaveOrUpdate({commit},params) {
            let res = await post("/epidemic/saveOrUpdate",params);
            // dispatch('pageQueryData')
            return res;
        },
        // 分页查询疫情数据
        async pageQueryData({commit},params) {
            let res = await get("/epidemic/pageQuery",params);
            commit("refreshPageQueryData",res.data)
            return res
        }
    }
}